use std::num::ParseIntError;
use actix_multipart::Multipart;
use std::iter::Map;
use std::fmt::Error;
use futures::StreamExt;
use std::collections::HashMap;

pub fn parse_usize(v:&str) ->Result<usize,ParseIntError>{
    let i:usize=v.parse()?;
    Ok(i)
}
pub fn parse_u64(v:String) ->Result<u64,ParseIntError>{
    let i:u64=v.parse()?;
    Ok(i)
}
pub fn parse_i64(v:String) ->Result<i64,ParseIntError>{
    let i:i64=v.parse()?;
    Ok(i)
}
pub fn parse_i32(v:String) ->Result<i32,ParseIntError>{
    let i=v.parse()?;
    Ok(i)
}
pub fn parse_i128(v:String) ->Result<i128,ParseIntError>{
    let i=v.parse()?;
    Ok(i)
}

pub async fn parse_multi(mut v:Multipart)->Result<HashMap<String,String>,Error>{
    let mut map=HashMap::new();
    while let Some( field) = v.next().await{
        let mut field =field.unwrap();

        let name=field.content_disposition().unwrap().get_name().unwrap().to_string();
        let bytes=field.next().await.unwrap().unwrap();
        let value=std::str::from_utf8(&bytes).unwrap().to_string();
        map.insert(name,value);

    }
    Ok(map)
}